<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
  <head>
  <base target="_self"/>
  
  <title>测试室添加人员</title>
  	<%@ include file="../jslib/jquerylib.jsp" %> 
	<link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js"  defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css" />
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/junyans/junyans.js"></script>

    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if> 
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var stateValue="";
    $().ready(function(){

		  $("#gridTableCeshis").jqGrid({
			url:common_basePath+'junyansAction!queryJunyansCeshis.action?junyansid='+$("#junyansid").val(),
			datatype: "json",
			height: 150,
			width: 720, 
			colNames:['主键','姓名','性别','职称','职务','科室','用户ID'],
			colModel:[
				{name:'ID',index:'ID', width:70,key:true,hidden:true}, 
				{name:'USERNAME',index:'USERNAME', width:100}, 
				{name:'SEX',index:'SEX', width:100,
				   formatter:function(cellvalue, options, rowObject) {
				       if (cellvalue==1){
				       	return "男";
				       }        
				       else{
				       	return "女";
				       }
				 }}, 
				{name:'ZHICHENGNAME',index:'ZHICHENGNAME', width:100}, 
				{name:'ZHIWUNAME',index:'ZHIWUNAME', width:100}, 
				{name:'ORG_NO',index:'ORG_NO', width:100},
				{name:'USERID',index:'USERID', width:100,hidden:true}
			],   
			shrinkToFit:false,
			sortname:'ID',
			sortorder:'asc',
			viewrecords:true,
			multiselect: true, // 是否显示复选框
			multiboxonly : true, 
			rownumbers: false,//显示行号
		    cellEdit: false,
			forceFit : true, 
			rowNum:200,
			mtype: "POST", 
			rowList:[15,20,50,200,500],
			toolbar: [false,"top"],
			jsonReader: {
				root:"rows",		// 数据行（默认为：rows）
				page: "page",  	// 当前页
				total: "total",  // 总页数
				records: "records",  // 总记录数
				repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
			},
			prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
			pager:"#gridPagerCeshis",
			caption: "测试室人员列表"
		});
		jQuery("#gridTableCeshis").jqGrid('navGrid','#gridPagerCeshis',{add:false,edit:false,del:false,search:false,refresh:false});	 
        
  
        //提交  
		var optionssubmit = {
	  	    url:'<%=request.getContextPath() %>/junyansAction!submitCeshistjry.action',
	  	    dataType:'json',
	  	    success: function(data) {
	  	      if(data.result=='success'){
				alert("提交成功");
				api.close();
				W.gridSearch();
	  	      }
	  	    }};

    	//提交
		$('#submitBtn').click(function(){
			if(!confirm("是否确认提交 ？")){
		   			return false;
			}
			
		    //判断样品和检测项目是否为空
		    var shejisIds = $("#gridTableCeshis").jqGrid('getDataIDs')+"";
		    if(!shejisIds){
		       alert("请添加测试室人员!");
		       return false;
		    }
		    
		    //获得下级角色
			var stepid = "";
			var stepttext = document.getElementById("steptype0");
			if (stepttext!=undefined){
				stepid=stepttext.value;
			}
			var params = {
				"flowid" : "${flowid}",
				"steptype" : stepid+""
			};
		    $.ajax({
					type: "POST",
					data : params,
					async: false,//取消异步提交
					url: '<%=request.getContextPath() %>/junyansAction!getNextSteptRoles.action',
					dataType: "json",
					success : function(data, textStatus) {  
						if(data.result=='success'){	
						    var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/chooseAllUser.jsp?roleid="+data.roles, window, "dialogWidth:930px;status:no;dialogHeight:500px");	
						    if (users != null&&users.length>0) {
				   		    var userIds = [];
				            var userNames = [];
				            	for(var i=0;i<users.length;i++){
					               userIds.push(users[i]['userid']);
					               userNames.push(users[i]['username']);
					            }
								document.getElementById("nextUserIds").value = ","+userIds+",";
								document.getElementById("nextUserNames").value = userNames;
							    $('#pageFrom').ajaxSubmit(optionssubmit);			
				            }		
						}else{
							alert(data.result)
						}
					}
			});
    	 });
    	 
    	$('#closeBtn').click(function(){
    		api.close();
		});
		
	});
	
  
   //添加设计所
   function selectCeshis(){
         if ($("#junyansid").val()==''){
         	alert('请先保存数据！');
         	return;
         }
         var userIDs = "";
         var ids = $("#gridTableCeshis").jqGrid('getDataIDs')+"";
         if (ids!=''){
         	 var arrayIDs = ids.split(',');
	         for(var i=0;i<arrayIDs.length;i++){
	         	 var row = jQuery("#gridTableCeshis").jqGrid('getRowData',arrayIDs[i]);//获取选中行.
	         	 userIDs+=row.USERID+",";
	         }
	         if (userIDs.length>0){
	         	userIDs = userIDs.substring(0,userIDs.length-1);
	         }
         }
		 var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/chooseAllUser.jsp?userid="+userIDs, window, "dialogWidth:930px;status:no;dialogHeight:500px");
   	 	 if (users != null) {
   		    var userIds = [];
            var userNames = [];
            for(var i=0;i<users.length;i++){
               userIds.push(users[i]['userid']);
               userNames.push(users[i]['username']);
            }
            $.ajax({
					type: "POST",
					async: false,//取消异步提交
					url: '<%=request.getContextPath() %>/junyansAction!addJunyansCeshis.action?userids='+userIds+'&junyansid='+$("#junyansid").val(),
					dataType: "json",
					success : function(data, textStatus) {  
						if(data.result=='success'){
						    //alert("添加成功！");	
						    gridSearchCeshis();									
						}else{
							alert("添加失败，请联系管理员！")
						}
					}
			});
         }
	}
   
   //删除设计所
   function deleteCeshis(){
		var ids= $("#gridTableCeshis").jqGrid("getGridParam", "selarrrow") + "";
		if (!ids) {
		    alert("请先选择记录!");  
		    return false;  
		}
		if(!confirm("是否确认删除？")){
			return false;
		}
		var params = {
					"ids": ids,
					"tableName":"kl_junyans_ceshis"
					};  
		var actionUrl = "<%=request.getContextPath() %>/auto!deleteForm.action";  
		$.ajax({  
			  url : actionUrl,  
		      type : "post", 
		      data : params,  
		      dataType : "json",  
		      cache : false,  
		      error : function(textStatus, errorThrown) {  
		          alert("系统ajax交互错误: " + textStatus.value);  
		      },  
		      success : function(data, textStatus) {
		      	if(data.result=='success'){
		      		alert("删除成功！");       
		      		gridSearchCeshis();
		      	}else{
		      		alert("删除失败！");
		      	}
		    }  
		});
	}
	
   //刷新设计所
   function gridSearchCeshis(){
        jQuery("#gridTableCeshis").jqGrid('setGridParam',
              {
                  url:'<%=request.getContextPath() %>/junyansAction!queryJunyansCeshis.action?junyansid='+$("#junyansid").val()
              }).trigger("reloadGrid", [{page:1}]); 
   }
   
	
   </script>
 	<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
  </head>
  
  <body style="overflow-y: scroll;">
     <form id="pageFrom" action="" enctype="multipart/form-data" method="post">

  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  		    <tr>
  		    	<td align="right">试验任务编号：</td>
  		    	<td colspan="3" align="left">
	  			    <input  type="text"  id="renwubh" maxlength="50" name="junyans.renwubh" 
	  			    style="border: 1px solid #999;height:25px;width: 738px;"  value="${junyans.renwubh}" />
	  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			    </td>
  		    </tr>
  			<tr>
  			  <td align="right">产品代号：</td>
  			  <td align="left">
  			    <input readonly type="text"  id="chanpindh" maxlength="50" name="junyans.chanpindh" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.chanpindh}" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">试验类型：</td>
  			  <td align="left">
  			     <select id="shiyanlx" name="junyans.shiyanlx" class='easyui-validatebox' style="border: 1px solid #999;height:25px;width:258px;height:30px;" >
 			      <option value="摸底试验" <s:if test='junyans.shiyanlx=="摸底试验"'>selected</s:if>>摸底试验</option>
			 	  <option value="性能攻关试验" <s:if test='junyans.shiyanlx=="性能攻关试验"'>selected</s:if>>性能攻关试验</option>
			 	  <option value="功耗试验" <s:if test='junyans.shiyanlx=="功耗试验"'>selected</s:if>>功耗试验</option>
			 	  <option value="定型试验" <s:if test='junyans.shiyanlx=="定型试验"'>selected</s:if>>定型试验</option>
			 	  <option value="寿命试验" <s:if test='junyans.shiyanlx=="寿命试验"'>selected</s:if>>寿命试验</option>
 			    </select>
 			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			   </td>
  			</tr>
  			<tr>
  			  <td align="right">负责人：</td>
  			  <td align="left">
  			    <input  type="text"  id="fuzher"  name="junyans.fuzher" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.fuzher}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">试验地点：</td>
  			   <td align="left">
  			    <input  type="text" id="shiyandd" maxlength="50" name="junyans.shiyandd" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.shiyandd}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			   </td>
  			</tr>
  			<tr>
  			  <td align="right">试验大纲：</td>
  			  <td align="left">
  			  	 <jsp:include page="../fileupload/attachment.jsp?id=${junyans.shiyandg}&column=shiyandg&show=y" ></jsp:include>
  			  	 <input type='hidden' name='shiyandg' id='shiyandg' value='${junyans.shiyandg}' />
  			  </td>
  			  <td align="right">涉密等级：</td>
  			  <td align="left">
  			    <input  type="text"  id="shemidj" readonly maxlength="50"  name="junyans.shemidj" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.shemidj}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
 			  </td>
  			</tr>
  			<tr>
  			  <td align="right">试验开始时间：</td>
  			  <td align="left">
  			    <input class="Wdate"  onClick="WdatePicker()"   type="text"  id="shiyankssj" maxlength="50"  name="junyans.shiyankssj" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.shiyankssj}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">预计结束时间：</td>
  			  <td align="left">
  			     <input class="Wdate"  onClick="WdatePicker()" type="text"  id="yujijssj" maxlength="50" name="junyans.yujijssj" 
  			     style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.yujijssj}"/>
  			     <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">阶段类型：</td>
  			  <td align="left">
  			    <input readonly  type="text"  id="jieduanlx" maxlength="50"  name="junyans.jieduanlx" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.jieduanlx}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">计划用弹量：</td>
  			  <td align="left">
  			     <input  type="text"  id="jihuaydl" maxlength="50" name="junyans.jihuaydl" 
  			     style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.jihuaydl}" />
  			     <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
		    <tr>
		    <td colspan='4' align='center'>
		      <div id='tt1' class='easyui-tabs' style='width:750px;height:320px'>
		      	<div title='测试室人员' style='padding:10px'>
		          <input id='btnselectCeshis' type='button'  value='选择人员' onclick="selectCeshis()" class='form_bt_orange'/>&nbsp;
				  <input id='btndeleteCeshis' type='button'  value='删 除' onclick="deleteCeshis()" class='form_bt_orange'/>
                  <table id="gridTableCeshis"></table>
                  <div id="gridPagerCeshis"></div></div>
                  
		        <div title='设计室人员' style='padding:10px'>
                  <table id="gridTableShejis"></table>
                  <div id="gridPagerShejis"></div></div>
                 
                <div title='测试项目' style='padding:10px'>
                  <table id="gridTableItem"></table>
                  <div id="gridPagerItem"></div>
				 </div>
			</td>
		</tr>
		</table>
		<input type="hidden" id="junyansid" name="junyansid" value="${junyans.id}" />
     	<input type="hidden" id="datatypeid" name="junyans.datatypeid" value="${junyans.datatypeid}" />
		<input type='hidden' id='flowtaskid' name='flowtaskid' value='${flowtaskid}'>
		<input type='hidden' id='taskinfoid' name='taskinfoid' value='${taskinfoid}'>
		<input type='hidden' id='flowid' name='flowid' value='${flowid}'>
		<input type='hidden' id='stateid' name='stateid' value='${stateid}'>
		<input type='hidden' id='nextUserIds' name='nextUserIds' >
		<input type='hidden' id='nextUserNames' name='nextUserNames' >
		${steptcontent }
		<table width="100%" border="0" align="center" class="formTableNew">
		  <tr>
			<td align="center">
		    	<input id="submitBtn" type="button" value="提 交" class="form_bt_orange" />
		    	<input id="btnback" type="button" value="退 回" class="form_bt_orange" onclick="backflow()"/>
		    	<input  id="closeBtn" type="button" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		  <tr>
		  	<td>&nbsp;&nbsp; </td>
		  </tr>
		</table>
	<!--表单结束-->
	</form>
  </body>
</html>
